//
//  CXVisiterController.swift
//  Project03-Weibo-swift
//
//  Created by w on 16/1/18.
//  Copyright © 2016年 w. All rights reserved.
//

import UIKit

class CXVisiterController: UITableViewController {
    
    var userlogin:Bool = CXUserInfoViewModel.sharedUserModel.isLogin
    /// 方便子类去获取这个自定义view
    var visiterView:CXVisiterView?
    
///  在该方法中重建view 根据是否登陆覆盖原有view
    override func loadView() {

        userlogin ? super.loadView() : customView()
    }
    //创建自定义view 并设置导航栏上的左右按钮内容
    private func customView(){
        let v = CXVisiterView()
        visiterView = v
        view = v
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "register")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", target: self, action: "login")
        
        visiterView?.registerBtn.addTarget(self, action: "registerClick", forControlEvents: .TouchUpInside)
        visiterView?.loginBtn.addTarget(self, action: "loginClick", forControlEvents: .TouchUpInside)

    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

extension CXVisiterController {
    
    //按钮响应方法
    @objc private func register(){
        print("注册")
    }
    @objc private func login() {
        print("登陆")
        //弹出登陆viewController
        presentViewController(CXNavigationController(rootViewController:CXOAuthController()), animated: true, completion: nil)
    }
    
    func registerClick() {
        register()
    }
    func loginClick() {
        login()
    }
}
